"""
@File         : router.py
@Time         : 2024/05/08 16:39:24
@Author       : Qrj
@Email        : 923207736@qq.com
@Description  : 通知公告相关路由
"""


from typing import Annotated

from fastapi import APIRouter, Depends

from src.business.admin.system.oauth2.token.dependencies.no_introduction import (
    DependVerifyAccessTokenMenumPermission,
)
from src.enums.permission_operation import PermissionOperationEnum
from src.utils.unified_response import SuccessApiJSONResponse

from .dependencies.route_depend import (
    route_depend_create_notice,
    route_depend_delete_notice,
    route_depend_get_notice,
    route_depend_list_background_notice,
    route_depend_list_forgeground_notice,
    route_depend_list_notice,
    route_depend_update_notice,
    route_depend_update_notice_status,
)
from .schemas.out import NoticeCompleteOutSchema, NoticeNoContentOutSchema

# 构建权限验证相关的依赖项
# 查
depend_select_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.select.value
)
# 增
depend_create_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.create.value
)
# 改
depend_update_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.update.value
)
# 删
depend_delete_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.delete.value
)

# 创建路由
router = APIRouter(
    prefix="/admin/system/notice",
    tags=[
        "通知公告接口",
    ],
)


@router.get("/get", summary="查询单个通知公告")
async def route_get_role(
    verify_menu_permission: Annotated[None, Depends(depend_select_permission_verify)],
    role: Annotated[NoticeCompleteOutSchema, Depends(route_depend_get_notice)],
):
    return SuccessApiJSONResponse(data=role)


@router.post("/list", summary="查询通知公告列表")
async def route_list_role(
    verify_menu_permission: Annotated[None, Depends(depend_select_permission_verify)],
    list_result: Annotated[
        tuple[list[NoticeNoContentOutSchema], int], Depends(route_depend_list_notice)
    ],
):
    search_pagination_result, search_total = list_result
    data = {"result": search_pagination_result, "total": search_total}
    return SuccessApiJSONResponse(data=data)


@router.get("/forgeground-notice-list", summary="获取前台通知公告列表")
async def route_list_forgeground_notice(
    # 由登录页面使用, 因此无需权限验证
    forgeground_notice_list: Annotated[
        list[NoticeCompleteOutSchema],
        Depends(route_depend_list_forgeground_notice),
    ],
):
    return SuccessApiJSONResponse(data=forgeground_notice_list)


@router.get("/background-notice-list", summary="获取后台通知公告列表")
async def route_list_background_notice(
    # 由登录页面使用, 因此无需权限验证
    background_notice_list: Annotated[
        list[NoticeCompleteOutSchema],
        Depends(route_depend_list_background_notice),
    ],
):
    return SuccessApiJSONResponse(data=background_notice_list)


@router.post("/create", summary="创建通知公告")
async def route_create_role(
    verify_menu_permission: Annotated[None, Depends(depend_create_permission_verify)],
    created_id: Annotated[int, Depends(route_depend_create_notice)],
):
    data = {"created_id": created_id}
    return SuccessApiJSONResponse(data=data)


@router.post("/update", summary="修改通知公告")
async def route_update_role(
    verify_menu_permission: Annotated[None, Depends(depend_update_permission_verify)],
    update_operation: Annotated[None, Depends(route_depend_update_notice)],
):
    return SuccessApiJSONResponse()


@router.post("/update-status", summary="修改通知公告状态")
async def route_update_role_status(
    verify_menu_permission: Annotated[None, Depends(depend_update_permission_verify)],
    update_status_operation: Annotated[
        None, Depends(route_depend_update_notice_status)
    ],
):
    return SuccessApiJSONResponse()


@router.post("/delete", summary="删除后台通知公告")
async def route_delete_user(
    verify_menu_permission: Annotated[None, Depends(depend_delete_permission_verify)],
    delete_operation: Annotated[None, Depends(route_depend_delete_notice)],
):
    return SuccessApiJSONResponse()
